package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.SignIntegralModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/30.
 */

public class SignIntegralActivityAdapter extends BaseAdapter {

    private Context mContext;
    List<SignIntegralModel> model= new ArrayList<>();
    int judgment=0;//0、签到 1、授信积分
    public SignIntegralActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem(SignIntegralModel models,int judgment){
        this.judgment=judgment;
        this.model.add(models);
        notifyDataSetChanged();
    }
    public void emptying(){
        this.model.clear();
       // notifyDataSetChanged();
    }
    public int number(){
      return   this.model.size();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.itme_sign_integral, null);
            holder.item_number = (TextView) convertView
                    .findViewById(R.id.item_number);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);
            holder.line1 = (LinearLayout) convertView
                    .findViewById(R.id.line1);
            holder.line = (TextView) convertView
                    .findViewById(R.id.line);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position==(model.size()-1)){
            holder.line.setVisibility(View.GONE);
            holder.line1.setVisibility(View.VISIBLE);
        }else {
            holder.line.setVisibility(View.VISIBLE);
            holder.line1.setVisibility(View.GONE);
        }

        if (judgment==0){
            SignIntegralModel signIntegralModel = model.get(position);
            holder.item_title.setText(signIntegralModel.getRemarks());
            holder.item_number.setText("+"+signIntegralModel.getVariablecontent());
            holder.item_time.setText(Sundry.getStrTime(1,signIntegralModel.getAddtime()));
        }else  if (judgment==1){
            SignIntegralModel signIntegralModel = model.get(position);
            holder.item_title.setText(signIntegralModel.getRemarks());
            if (signIntegralModel.getDirectionofchange().equals("2")){
                holder.item_number.setText("+"+signIntegralModel.getChangenum());
            }else {
                holder.item_number.setText("-"+signIntegralModel.getChangenum());
            }

            holder.item_time.setText(Sundry.getStrTime(1,signIntegralModel.getAddtime()));
        }
        return convertView;
    }

    class ViewHolder {
        TextView item_title;
        TextView item_time;
        TextView item_number;
        LinearLayout line1;
        TextView line;

    }
}

